<script setup lang="ts">
  import { ref, defineEmits, computed, watch, onMounted } from 'vue';
  import { useBooleanStore } from '@/store';
  import { searchByCar } from '@/api/les';

  const emit = defineEmits(['updateArray']);
  const booleanStore = useBooleanStore();
  // 表单查询数据
  const carCode = ref<string>('');
  const carUser = ref<string>('');
  // const carSeat = ref<string>('');

  const pageSize = ref<number>(10);
  const pageNumber = ref<number>(1);
  // 发送搜索数据
  // const flowQueryData = ref({
  //   searchParams: computed(() => ({
  //     carCode: carCode.value,
  //     carUser: carUser.value,
  //     // carSeat: carSeat.value,
  //     // status: '',
  //     // carName: '',
  //     // remark: '',
  //   })),
  //   pageParameter: computed(() => ({
  //     rows: pageSize.value,
  //     page: pageNumber.value,
  //   })),
  // });
  // 表格数据

  async function handleSearch() {
    const newData = await searchByCar({
      carCode: carCode.value,
      carUser: carUser.value,
      current: pageNumber.value,
      size: pageSize.value,
    });
    emit('updateArray', newData);
  }
  // 重置
  function reset() {
    carCode.value = '';
    carUser.value = '';
    // carSeat.value = '';
    handleSearch();
  }
  onMounted(() => {
    handleSearch();
  });
  // 监听分页
  watch([() => booleanStore.pageNum, () => booleanStore.pageSize], () => {
    if (booleanStore.num5 === 40) {
      pageNumber.value = booleanStore.pageNum;
      pageSize.value = booleanStore.pageSize;
      handleSearch();
    }
  });
  watch(
    () => booleanStore.update,
    () => {
      if (booleanStore.num6 === 17) handleSearch();
    }
  );
</script>

<template>
  <a-row :gutter="{ md: 8, lg: 24, xl: 32 }">
    <a-col :span="6">
      <div>
        <a-input v-model="carCode" placeholder="料车编号" size="large" />
      </div>
    </a-col>
    <a-col :span="6">
      <div>
        <a-input v-model="carUser" placeholder="料车使用人" size="large" />
      </div>
    </a-col>
    <!-- <a-col :span="6">
      <div>
        <a-input v-model="carSeat" placeholder="小车所属站位" size="large" />
      </div>
    </a-col> -->
  </a-row>

  <div class="btn-group">
    <a-button type="primary" size="large" @click="handleSearch">查询</a-button>
    <a-button class="btn-reset" size="large" @click="reset">重置</a-button>
    <a-button
      type="primary"
      class="btn-reset"
      size="large"
      @click="booleanStore.toggleBool(7)"
      >新增</a-button
    >
  </div>
</template>

<style scoped>
  .btn-group {
    float: right;
    margin-top: 15px;
  }

  .btn-reset {
    margin-left: 10px;
  }
</style>
